package com.sanyang.lawyer.controller.Case_law;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.sanyang.lawyer.ResultApi.CodeMsg;
import com.sanyang.lawyer.ResultApi.ResponseResult;
import com.sanyang.lawyer.entity.Case_court;
import com.sanyang.lawyer.entity.Case_law;
import com.sanyang.lawyer.service.Case.Case_courtService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("case_count")
public class Case_courtController {

    @Autowired
    private Case_courtService courtService;
    
    private ObjectMapper objectMapper = new ObjectMapper();
    

    //根据id查询一条记录
    @RequestMapping("queryByid")
    public ResponseResult<Case_court> queryByid(int court){
        return ResponseResult.success(courtService.queryByid(court));
    }

    //获取所有法院
    @RequestMapping("selectList")
    public ResponseResult<List<Case_court>> selectAll(){
        return ResponseResult.success(courtService.selectAll());
    }
    
    
    //查询出所有案件和法院关联的信息
    @RequestMapping("queryCourtByLaw")
    public ResponseResult<List<Case_law>> queryCourtByLaw(String data){
        Case_law case_law = null;
        if(data != null){
            try {
                case_law = objectMapper.readValue(data, Case_law.class);
            } catch (IOException e) {
                //错误返回服务器正忙错误
                ResponseResult.error(CodeMsg.SERVER_BUSY);
            }
        }
        return ResponseResult.success(courtService.queryCourtByLaw(case_law));
    }
    
    //根据案件id修改案件对应的日期。
    @RequestMapping("update_courtTime")
    public ResponseResult<String> update_courtTime(String data){
        Case_law case_law = null;
        try {
            case_law = objectMapper.readValue(data, Case_law.class);
        } catch (IOException e) {
            //错误返回服务器正忙错误
            ResponseResult.error(CodeMsg.SERVER_BUSY);
        }
        courtService.update_courtTime(case_law);
        return ResponseResult.success("成功修改！~");
    }
    
    
    
}
